#include <iostream>
#include "RelationBinaireLogique.hpp"

using namespace std;

RelationBinaireLogique::RelationBinaireLogique ( Expression* opGauche, enum TypeRelationBinaireLogique type, Expression* opDroit )
{
  typeRelation = type;
  _opGauche=opGauche;
  _opDroit=opDroit;
}

RelationBinaireLogique::~RelationBinaireLogique ()
{
  delete _opGauche;
  delete _opDroit;
}

void RelationBinaireLogique::compute ()
{
  LOGFUNCTION ( IEXEC_LOG );
  _opGauche->compute();
  _opDroit->compute();
  switch(typeRelation){
  case RBLAnd: getValue()=_opGauche->getValue()&&_opDroit->getValue(); break;
  case RBLOr:  getValue()=_opGauche->getValue()||_opDroit->getValue(); break;
  case RBLEq:  getValue()=_opGauche->getValue()==_opDroit->getValue(); break;
  case RBLNeq: getValue()=_opGauche->getValue()!=_opDroit->getValue(); break;
  case RBLLt:  getValue()=_opGauche->getValue()<_opDroit->getValue(); break;
  case RBLLte: getValue()=_opGauche->getValue()<=_opDroit->getValue(); break;
  case RBLGt:  getValue()=_opGauche->getValue()>_opDroit->getValue(); break;
  case RBLGte: getValue()=_opGauche->getValue()>=_opDroit->getValue(); break;
  }

}

void RelationBinaireLogique::display ( const unsigned int shift) const
{
  cout << "(";
  _opGauche->display();
  switch(typeRelation)
    {
    case RBLAnd: cout << "&&"; break;
    case RBLOr: cout << "||"; break;
    case RBLEq: cout << "=="; break;
    case RBLNeq: cout << "!="; break;
    case RBLLt: cout << "<"; break;
    case RBLLte: cout << "<="; break;
    case RBLGt: cout << ">"; break;
    case RBLGte: cout << ">="; break;
    }
  _opDroit->display();
  cout << ")";
}
